<template>
  <div class="login-icon">
    <div class="flex">
      <div class="flex" style="flex: 1">
        <img
          class="imgbutton"
          @click="prev()"
          src="@/assets/img/title/login-left.svg"
        />
      </div>
      <div id="movebox" style="flex: 4">
        <div id="login-icon-box" :style="TransFormStyle">
          <div class="icon-item" ref="inconitem">
            <img class="imgbutton" src="@/assets/img/title/wechat.svg" />
          </div>
          <div class="icon-item">
            <img class="imgbutton" src="@/assets/img/title/qq.svg" />
          </div>
          <div class="icon-item">
            <img class="imgbutton" src="@/assets/img/title/blog.svg" />
          </div>
          <div class="icon-item">
            <img class="imgbutton" src="@/assets/img/title/tb.svg" />
          </div>
          <div class="icon-item">
            <img class="imgbutton" src="@/assets/img/title/zfb.svg" />
          </div>
        </div>
      </div>
      <div class="flex" style="flex: 1">
        <img
          class="imgbutton"
          @click="next()"
          src="@/assets/img/title/login-right.svg"
        />
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "loginicon",
  data() {
    return {
      Distance: 0,
    };
  },
  methods: {
    next() {
      if (this.Distance <= -this.MaxDistance) {
        this.Distance = 0;
      } else {
        this.Distance -= this.MoveDistance;
      }
    },
    prev() {
      if (this.Distance >= 0) {
        this.Distance -= this.MaxDistance;
      } else {
        this.Distance += this.MoveDistance;
      }
    },
  },
  computed: {
    MoveDistance() {
      return document.getElementsByClassName("icon-item")[0].clientWidth;
    },
    TransFormStyle() {
      return {
        transform: "translateX(" + this.Distance + "px)",
      };
    },
    Maxfrequency() {
      let itemarr = document.getElementsByClassName("icon-item");
      let iconwidth = 0;
      for (let i = 0; i <= itemarr.length - 1; i++) {
        iconwidth += itemarr[i].clientWidth;
      }
      let i =
        (iconwidth - document.getElementById("movebox").clientWidth) /
        this.MoveDistance;
      return i;
    },
    MaxDistance() {
      return this.Maxfrequency * this.MoveDistance;
    },
  },

};
</script>

<style scoped>
.login-icon {
  width: 240px;
  height: 50px;
}

#login-icon-box {
  height: 50px;
  width: 160px;
  position: relative;
  transition: all 0.3s;
  display: flex;
}

.imgbutton {
  width: 15px;
  cursor: pointer;
  transition: all 0.3s;
}

.imgbutton:hover {
  opacity: 0.7;
}

.icon-item {
  flex-shrink: 0;
  height: 50px;
  width: 33.3%;
  display: flex;
  justify-content: center;
  align-items: center;
}
.icon-item img {
  width: 20px;
}
#movebox {
  overflow: hidden;
}
</style>
